|
|
|
|
|
|
|
Figure 8.23.
Using TOP n to limit the result set. |
|
|
|
|
|
|
|
|
Notice that the preceding example uses the DESC keyword in the ORDER BY clause. Whether you use the DESC or ASC ORDER BY format, the result set still contains the first n records in the table (based on the sort). Also note that the result set contains more than five records, because several records have the same Sales value. |
|
|
|
|
|
|
|
|
The TOP n PERCENT version returns not the top five records, but the top five percent of the records in the underlying data table. The results of the following SQL statement (see Figure 8.24) contain several more records than the result set shown previously. |
|
|
|
|
|
|
|
|
SELECT TOP 5 PERCENT * FROM BookSales
ORDER BY Sales |
|
|
|
|
|
|
|
|
Figure 8.24.
Using TOP n PERCENT to limit the result set. |
|
|
|
|
|